const { Router } = require('express')
const express = require('express')
//路由容器
const conservator = express.Router()
const axios = require('axios')
const jwt = require("jsonwebtoken")//解析token

conservator.get('/power', (req, res) => {
    res.render('admin/index',{userInfo: jwt.decode(req.session.token)})
})
// 跳转到个人信息页面
conservator.get('/personData', (req, res) => {
    // let {userId} = req.query;
    axios({
        url: `consumer/findById`,
        method: 'GET',
        params: {
            userId:jwt.decode(req.session.token).userId
        }
    })
    .then(data => {
        console.log("---------个人信息-------");
        console.log(data.data);
        res.render('admin/personData',{
            info:data.data.data,
            userInfo: jwt.decode(req.session.token)
        })
        console.log(data.data)
    })
    .catch(err => {
        console.log(err);
    })
})
// 管理员列表
conservator.get('/conservatorList', (req, res) => {
    res.render('admin/conservatorList',{
        userInfo: jwt.decode(req.session.token)
    })
})

// 查询所有管理员
conservator.get('/findUsersByClass', (req, res) => {
    let {page ,size } = req.query;
    console.log("ManagerUsers");
    console.log(req.body);
    axios({
        url: `superConsumer/findUsersByClass/2`,
        method: 'GET',
        params: {
            page: page,
            size: size,
        }
    })
    .then(data => {
        res.send(data.data)
        console.log(data.data)
    })
    .catch(err => {
        console.log(err);
    })
})
module.exports=conservator;